# -*- coding: utf-8 -*-
'''
@文件    :routeclass.py
@说明    :
@时间    :2025/08/09 23:56:30
@作者    :浪晋
@版本    :1.0
'''
import time
from typing import Callable, Coroutine, Any
from fastapi import Request
from fastapi.routing import APIRoute
from fastapi.responses import Response
from app.core.database import record_request_log
from app.settings.config import config


class OperationLogRoute(APIRoute):
    def get_route_handler(self) ->  Callable[[Request], Coroutine[Any, Any, Response]]:
        original_route_handler = super().get_route_handler()

        async def operation_route_handler(request: Request) -> Response:
            response = await original_route_handler(request)
            response = await record_request_log(request, response)
            return response
        return operation_route_handler